package com.xtx.mapper;

import com.xtx.annotation.AutoFill;
import com.xtx.entity.ShoppingCart;
import com.xtx.enumeration.OperationType;
import com.xtx.vo.ShoppingCartVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingMapper {


    @AutoFill(value = OperationType.INSERT)
    void addShoppingCart(ShoppingCart shoppingCart);
    

    @Select("select id,name,picture,price,count,sku_id,attrs_text,selected from shopping_cart where user_id = #{id}")
    List<ShoppingCartVO> getShoppingCartList(Integer id);
    
    void updataShoppingCart(ShoppingCart shoppingCart);

    @Select("select id,name,picture,price,count,sku_id,attrs_text,selected from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> getShoppingCart(Integer userId);

    @Delete("delete from shopping_cart where id = #{id}")
    void deleteShoppingCart(Integer id);

    @Update("update shopping_cart set selected = #{selected} where user_id = #{userId}")
    void checkAll(Integer userId, Integer selected);

    @Select("select * from shopping_cart where user_id = #{currentId} and selected = 1")
    List<ShoppingCart> getShoppingCartByUserId(Long currentId);

    @Delete("delete from shopping_cart where user_id = #{currentId} and selected =1")
    void deleteShoppingCartByUserId(Long currentId);
}
